import os
from TemplateSolver import TemplateSolver
from str_color import bcolors
from ai_alg_generator import *
from GameManager import GameManger
from ab_alg_generator import ABSolver


def task_loop(nums, solver_1, solver_2):
    solver_1_win_times = 0
    solver_2_win_times = 0
    for i in range(nums):
        gameInstance = GameManger(1, 2, (i+1) % 2)
        winner = gameInstance.auto_game_loop(
            use_solver=True, solver_1=solver_1, solver_2=solver_2, is_print_board=True, is_print_final_board=True)
        if winner == 1:
            solver_1_win_times += 1
        if winner == 2:
            solver_2_win_times += 1

    return (solver_1_win_times / nums), (solver_2_win_times / nums)


if __name__ == '__main__':
    solver = ABSolver()
    # solver = TemplateSolver(negamax)
    solver_ = TemplateSolver(Cupidity)
    # gameInstance = GameManger(1, 2, 1, is_print_board = True, is_print_final_board = True)
    # gameInstance.auto_game_loop(use_solver = True, solver_1 = solver, solver_2 = solver_ ,is_print_board = True, is_print_final_board = True)
    # gameInstance.auto_game_loop(use_solver = True, solver_1 = solver, solver_2 = solver_,is_print_board = True, is_print_final_board = True)
    task_time = 10
    rate1, rate2 = task_loop(task_time, solver, solver_)
    print(rate1, rate2)

    with open('../data/record.txt', 'a') as f:
        str = (
            f"\nrate1 = {rate1}\nrate2 = {rate2}\ntask_time = {task_time}\n")
